import QtQuick 1.1
import com.nokia.meego 1.0

Page {
    id:pageCreate

    width: 854
    height: 480

    lockInLandscape: true
    orientationLock: PageOrientation.LockLandscape


    //The background
    Image {
        id: background
        source: "images/createAndJoinBg.png"
        x: 0
        y: 0
        z: -1
    }


    //button to go back to the previous page
    Image {
        id: backButton
        source: "images/backButton.png"
        opacity: 0.7 //The opacity is changed when pressed so that the user know that the touch is being detected
        x: 0
        y: 0

        MouseArea {
            anchors.fill: parent
            onPressed: parent.opacity = 1 //When the user touches the button, it goes totally opaque...
            onReleased: parent.opacity = 0.7 //...But when released, it returns to the original opacity
            onClicked: {
                BluetoothManager.stopServer();
                pageCreate.pageStack.pop();
            }
        }
    }

    Label {
        id: label1
        text: "Waiting for a player to join"
        anchors.bottom: rotatingImage.top
        anchors.horizontalCenter: parent.horizontalCenter

    }

    Image {
        id: rotatingImage
        source: "images/loading.png"
        anchors.centerIn: parent

        states: State {
            name: "rotated"
            PropertyChanges { target: rotatingImage; rotation: 180 }
        }

        transitions: Transition {
            RotationAnimation { duration: 2000; direction: RotationAnimation.Counterclockwise; loops: Animation.Infinite }
        }

        //Starts the animation automatically
        Component.onCompleted: rotatingImage.state = "rotated"
    }

    // Signal handler for network signals
    Item {
        Connections {
            target: BluetoothManager
            onClientConnected: {
                pageCreate.pageStack.push(Qt.resolvedUrl("GamePage.qml"));
            }
        }
    }
}
